/**
 *  系统日志管理里接口文件
 * @autor 2655251652
 */
import { req } from '@/util/request'
import type { Page, PageOprion, ResData } from '@/types/index'
import type { LogTable } from '@/types/log'
import type { AxiosProgressEvent, AxiosResponse } from 'axios'

/**
 * 查询系统日志
 * @param page 分页参数
 * @param cdn 查询参数
 * @returns
 */
export function getLogHandle(
  page: PageOprion,
  cdn: LogTable,
  order: string = ''
): ResData<Page<LogTable>> {
  return req.post('/log/get/handle', {
    size: page.size,
    num: page.num,
    cdn: {
      username: cdn.username,
      order: {
        time: order
      },
      hid: (cdn.hid as number[]).length == 0 ? null : cdn.hid,
      time: cdn.time
    }
  })
}

/**
 * 查询系统日志
 * @param page 分页参数
 * @param cdn 查询参数
 * @returns
 */
export function getLogSign(
  page: PageOprion,
  cdn: LogTable,
  order: string = ''
): ResData<Page<LogTable>> {
  return req.post('/log/get/sign', {
    size: page.size,
    num: page.num,
    cdn: {
      username: cdn.username,
      order: {
        time: order
      },
      hid: (cdn.hid as number[]).length == 0 ? null : cdn.hid,
      time: cdn.time
    }
  })
}
/**
 * 删除某日志
 * @param data id列表
 * @returns
 */
export function delLog(data: number[]): ResData<any> {
  return req.post('/log/delete', data)
}

/**
 *
 * @param type 接口类型
 * @param cdn 条件
 * @returns
 */
export function clearLog(type: 'handle' | 'sign', cdn: LogTable): ResData<any> {
  return req.post('/log/clear', {
    type,
    cdn
  })
}

/**
 * 按条件导出接口日志
 * @param type 接口类型
 * @param cdn 查询条件
 * @returns 日志数据
 */
export function exportLog(
  type: 'handle' | 'sign',
  cdn: LogTable,
  progress: (e: AxiosProgressEvent) => void
): ResData<LogTable[]> {
  return req.post(
    '/log/export',
    {
      type,
      cdn
    },
    {
      onDownloadProgress: progress
    }
  )
}
